$('form').submit(function(event) {
    event.preventDefault();
    var formData = $(this).serializeObject();
    var jsonData = JSON.stringify(formData);
    $.ajax({
        url: $('form').attr('action') ,
        type: $('form').attr('method') ,
        data: jsonData,
        contentType: 'application/json',
        success: function(response) {
            console.log('Data submitted successfully', response);
        },
        error: function(error) {
            console.error('Error submitting data:', error);
        }
    });
});

/**
 * 自动将form表单封装成json对象
 */
$.fn.serializeObject = function() {
    var o = {};
    var a = this.serializeArray();
    $.each(a, function() {
        if (o[this.name]) {
            if (!o[this.name].push) {
                o[this.name] = [ o[this.name] ];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};
